package org.jmat.domain.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

/**
 * The class is superclass of a animal.
 * @author Mathieu Chatelain
 */

@Entity(name="Animal")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
		name = "ANIMAL_TYPE",
		discriminatorType = DiscriminatorType.STRING
)
public abstract class Animal implements Serializable{

	private static final long serialVersionUID = 408005680385098917L;
	protected Integer id;
	protected String name;
	protected Date birthday;
	protected Double weight;
	protected Person prop;
	

	/**
	 * 
	 * @return Integer - Id of an animal
	 */
	@Id
	@Column(name = "ID", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}
	/**
	 * 
	 * @param id - set id of an animal
	 */
	public void setId(Integer id) {
		this.id = id;
	}
	/**
	 * 
	 * @return String - name of an animal
	 */
	public String getName() {
		return name;
	}
	/**
	 * 
	 * @param name - set name of an animal
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * 
	 * @return Date - birthday of an animal
	 */
	public Date getBirthday() {
		return birthday;
	}
	/**
	 * 
	 * @param birthday - set birtdhay of an animal
	 */
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	/**
	 * 
	 * @return Double - weight of an animal
	 */
	public Double getWeight() {
		return weight;
	}
	/**
	 * 
	 * @param weight - set weight of an animal
	 */
	public void setWeight(Double weight) {
		this.weight = weight;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "prop_id", nullable = false)
	public Person getProp() {
		return prop;
	}
	public void setProp(Person prop) {
		this.prop = prop;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((birthday == null) ? 0 : birthday.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Animal other = (Animal) obj;
		if (birthday == null) {
			if (other.birthday != null)
				return false;
		} else if (!birthday.equals(other.birthday))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
}
